import { UPDATE_USER, SET_USER } from './constants'
import axios from 'src/utils/http'

export default {
  async [UPDATE_USER](context: { state: { user: { username: any } }; commit: (arg0: string, arg1: any) => void }) {
    const res = await axios.get(`/profiles/${context.state.user.username}`)
    const profile = res.data.profile
    const newUser = {
      ...context.state.user,
      username: profile.username,
      image: profile.image,
      bio: profile.bio
    }
    context.commit(SET_USER, newUser)
  }
}